const fs = require('fs');
const path = require('path');

module.exports = function (pagePath, name) {
  if (!fs.existsSync(pagePath)) {
    fs.mkdirSync(pagePath);
  }
  const indexFile = pagePath + `/index.js`;
  if (!fs.existsSync(indexFile)) {
    const template = [];
    template.push(`import { connect } from 'react-redux';  `);
    template.push(`import { ${name}Action } from './action';  `);
    template.push(`import ${name} from './component/${name}';`);
    template.push(`  `);
    template.push(`const mapStateToProps = (state) => {  `);
    template.push(`  return {};`);
    template.push(`};  `);
    template.push(`  `);
    template.push(`const mapDispatchToProps = {  `);
    template.push(`  `);
    template.push(`};  `);
    template.push(`  `);
    template.push(`export default connect(mapStateToProps, mapDispatchToProps)(${name});  `);
    template.push(`  `);
    fs.writeFileSync(indexFile, template.join('\n'));
  }

}
